<template>
  <div class="big_box_qian">
    <main>
      <div class="mainbo">
        <div class="mainbo-1">
          <el-form>
            <el-row :gutter="20">
              
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-form-item label="服务包">
                    <el-select v-model="service.serviceId" clearable>
                      <el-option
                        v-for="item in service"
                        :key="item.serviceId"
                        :label="item.serviceType"
                        :value="item.serviceId"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="grid-content bg-purple">
                  <el-form-item label="签约机构">
                    <el-select v-model="mechanism.mechanismId" clearable>
                      <el-option
                        v-for="item in mechanism"
                        :key="item.mechanismId"
                        :label="item.mechanismType"
                        :value="item.mechanismId"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <div class="grid-content1 bg-purple">
                  <el-form-item label="过期时间">
                    <el-form-item>
                      <el-date-picker
                        v-model="list.staterDate"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        clearable
                        @change="statime"
                        type="date"
                        :picker-options="startDatePicker"
                      >
                      </el-date-picker>
                      至
                      <el-date-picker
                        v-model="list.endDate"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        clearable
                        @change="wfsjEnd"
                        type="date"
                        :picker-options="endDatePicker"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content1 bg-purple">
                  <el-form-item label="">
                    <el-input
                      v-model="list.record_name"
                      clearable
                      placeholder="请输入名称"
                      style="200px"
                      id="n-2"
                    >
                      <!-- clearable 输入框可清除属性 -->
                    </el-input>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="6">
                <div class="grid-content1 bg-purple">
                  <el-button type="primary" @click="onSubmit">查询</el-button>
<el-button type="success" @click="add">新增待签约</el-button>
                  <el-button type="info" @click="dc">导出</el-button>
                </div>
              </el-col>
            </el-row>
          </el-form>
        </div>

        <!-- 表格 -->
        <div id="mainma">
          <el-table
            ref="multipleTable"
            :data="
              list.slice((currentPage - 1) * pageSize, currentPage * pageSize)
            "
            tooltip-effect="dark"
            style="width: 95%; margin: 0 auto"
            :header-cell-style="{ background: 'silver', color: '#606266' }"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              :id="list.record_id"
              v-model="list.record_id"
              width="30"
            >
            </el-table-column>
            <el-table-column
              prop="record_id"
              width="100px"
              label="编号"
            ></el-table-column>
            <el-table-column prop="record_name" width="60px" label="签约人姓名">
              <template slot-scope="list">
                <p v-html="list.row.record_name"></p>
              </template>
            </el-table-column>
            <el-table-column
              prop="record_card"
              label="身份证号"
              width="140px"
            ></el-table-column>
            <el-table-column
              prop="record_phone"
              width="120px"
              label="手机号"
            ></el-table-column>
            <el-table-column
              prop="record_doctor_team"
              width="100px"
              :formatter="formatState2"
              label="签约医生团队"
            ></el-table-column>
            <el-table-column
              prop="record_doctor"
              label="签约医生"
              width="60px"
            ></el-table-column>
            <el-table-column
              prop="record_server"
              width="140px"
              label="服务包"
              :formatter="formatState"
            ></el-table-column>
            <el-table-column prop="record_state" width="80px" label="签约状态">
              <template slot-scope="scope">
                <span style="color: #6c76f4" v-if="scope.row.record_state === 1"
                  >待处理</span
                >
                <span style="color: #6c76f4" v-if="scope.row.record_state === 2"
                  >待处理</span
                >
              </template>
            </el-table-column>
            <el-table-column
              prop="record_organization"
              label="签约机构"
              :formatter="formatState4"
            ></el-table-column>
            <el-table-column
              prop="record_date"
              label="到期时间"
            ></el-table-column>
            <el-table-column prop="" label="操作" width="300px">
              <template slot-scope="scope">
                
                <el-button type="danger" @click="look2(scope.row.record_id)"
                  >编辑 <i class="el-icon-edit"></i
                ></el-button>
                <el-button type="success" @click="look3(scope.row.record_id)"
                  >签约<i></i
                ></el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页器 -->
          <div class="block" style="margin-top: 15px">
            <el-pagination
              align="center"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[1, 5, 10, 20]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="list.length"
            >
            </el-pagination>
          </div>
        </div>
        <div id="pp"></div>
      </div>
    </main>
  </div>
</template>

<script>
import { export2Excel } from "../util";
export default {
  data() {
    return {
      list: [], // 商品所有数据
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页的数据条数
      stateList: {
        state: null,
      },
      state: [], //状态
      service: [], //服务包
      mechanism: [], //签约机构
      columns: [
        { title: "编号", key: "record_id" },
        { title: "签约人姓名", key: "record_name" },
        { title: "身份证号", key: "record_card" },
        { title: "手机号", key: "record_phone" },

        { title: "服务状态", key: "record_state" },
        { title: "签约医生团队", key: "record_doctor_team" },
        { title: "签约服务包", key: "record_server" },
        { title: "申请时间", key: "audit_time" },
        { title: "备注", key: "signeda_note " },
      ],
    };
  },
  mounted() {
    // 不必在自己引入axios变量, 而是直接使用全局属性$axios
    this.$axios({
      url: "api/record/findRecord1",
      mounted: "GET",
    }).then((res) => {
      console.log(res);
      this.list = res.data.data;
    });
    this.$axios({
      url: "api/state/findState",
      mounted: "GET",
    }).then((res) => {
      console.log(res);
      this.state = res.data;
    });
    this.$axios({
      url: "api/serProject/findService",
      mounted: "GET",
    }).then((res) => {
      console.log(res);
      this.service = res.data;
    });
    this.$axios({
      url: "api/mechanism/findMechanism",
      mounted: "GET",
    }).then((res) => {
      console.log(res);
      this.mechanism = res.data;
    });
  },
  methods: {
    dc() {
      export2Excel(this.columns, this.list, "待处理签约表");
    },
    look(val) {
      this.$router.push({ path: "/ViewDetailss", query: { idpp: val } });
    },
    look2(val) {
      this.$router.push({ path: "/ViewDetailssss", query: { idpp: val } });
    },
    add() {
      this.$router.push({ path: "/add" });
    },
    look3(val) {
      this.$axios({
        url: "api/record/updateStateById",
        mounted: "GET",
         params:{
               record_id: val
             }
      })
       this.$message('签约成功');
        window.location.reload()
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      //   alert(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    formatState: function (row, column, cellValue) {
      if (cellValue === 1) {
        return "0-6岁儿童服务包";
      } else if (cellValue === 2) {
        return "老年人服务包";
      } else if (cellValue === 3) {
        return "慢性病护理包";
      }
    },
    formatState2: function (row, column, cellValue) {
      if (cellValue === 1) {
        return "王皓团队    ";
      } else if (cellValue === 2) {
        return "胡曼团队";
      } else if (cellValue === 3) {
        return "李维团队";
      }
    },
    formatState4: function (row, column, cellValue) {
      if (cellValue === 1) {
        return "罗西社区服务中心 ";
      } else if (cellValue === 2) {
        return "天明社区服务中心";
      } else if (cellValue === 3) {
        return "民进社区服务中心";
      }
    },
    onSubmit() {
      // alert(this.mechanism.mechanismId)
      this.$axios({
        url: "api/record/findRecord1",
        mounted: "GET",
        params: {
          record_name: this.list.record_name,
          record_state: this.state.stateId,
          staterDate: this.list.staterDate,
          endDate: this.list.endDate,
          record_server: this.service.serviceId,
          record_organization: this.mechanism.mechanismId,
        },
      }).then((res) => {
        console.log(res);
        this.list = res.data.data;
      });
    },
  },
};
</script>

<style>
.grid-content {
  min-height: 50px;
  border-radius: 4px;
  margin-top: 50px;
}
.grid-content1 {
  min-height: 50px;
  border-radius: 4px;
  margin-top: 30px;
}
#pp {
  width: 100%;
  height: 100px;
}
.b-1 {
  margin-left: 1000px;
}
#n-1 {
  margin-top: 20px;
}
.bel-1 {
  margin-left: 50px;
  width: 300px;
  margin-top: 30px;
}
.bel-2 {
  margin-left: 50px;
  width: 300px;
  margin-top: 30px;
}
.bel-3 {
  margin-left: 50px;
  width: 300px;
  margin-top: 30px;
}
#time {
  margin-top: 20px;
  margin-left: 50px;
}
.mainbo-1 {
  width: 94%;
  height: 230px;
  margin-left: 3%;
  float: left;
  position: relative;
  background-color: #fff;
}
.mainbo {
  float: left;
  background-color: #fff;
  width: 94%;
  margin-left: 3%;
}
.mainma {
  float: left;
  margin-top: 40px;
}
.butttt {
  float: left;
  margin-left: 1000px;
}
</style>